package com.bckj.fastboot.flow.model;

import com.bckj.fastboot.flow.process.BpmnVisitor;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Getter
@Setter
public class BpmnProcess {
    private final String id;
    private final String name;
    private final List<BpmnElement> startEvents;
    private final List<BpmnServiceTask> serviceTasks;
    private final Map<String, BpmnElement> elements;
    private Integer version;


    public BpmnProcess(String id, String name) {
        this.id = id;
        this.name = name;
        startEvents = new ArrayList<>();
        serviceTasks = new ArrayList<>();
        elements = new HashMap<>();
    }

    public void addServiceTask(BpmnServiceTask serviceTask) {
        serviceTasks.add(serviceTask);
    }

    public void addElement(BpmnElement element) {
        elements.put(element.getId(), element);
    }

    public BpmnElement getElementById(String id) {
        return elements.get(id);
    }

    public void execute(BpmnVisitor visitor) {
        for (BpmnElement element : startEvents) {
            element.accept(visitor);
        }
    }
}